package org.daochong.lang;

import java.util.List;

public class PageResult<T> implements java.io.Serializable{
	
	private static final long serialVersionUID = 1L;
	private int page;
	private int pageSize;
	private int count;
	private int pageCount;
	private List<T> data;

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
		calc();
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
		calc();
	}

	public int getPageCount() {
		return pageCount;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	private void calc() {
		if (this.getPageSize() <= 0) {
			this.setPageSize(20);
		}
		if (this.getCount() == 0) {
			this.pageCount = 0;
		} else {
			this.pageCount = this.getCount() / this.getPageSize()
					+ (this.getCount() % this.getPageSize() == 0 ? 0 : 1);
		}
	}
}
